package collection.Demo01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @Author Miku
 * @Create 2021/4/12 14:56
 * Collection接口的使用
 */
public class Test {
    public static void main(String[] args) {
        //创建集合
        Collection collection = new ArrayList();
        collection.add("苹果");
        collection.add("西瓜");
        collection.add("香蕉");
        System.out.println("元素个数:"+collection.size());
        System.out.println(collection);

        System.out.println("---------------------");
        for (Object object : collection) {
            System.out.println(object);
        }

        System.out.println("---------------------");
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            String s = (String) it.next();
            System.out.println(s);
        }

        System.out.println("---------------------");
        System.out.println(collection.contains("西瓜"));
        System.out.println(collection.isEmpty());

    }
}
